<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>module Gem::Security - rubygems: Ruby Standard Library Documentation</title>


<script src="../js/navigation.js" defer></script>
<script src="../js/search.js" defer></script>
<script src="../js/search_index.js" defer></script>
<script src="../js/searcher.js" defer></script>
<script src="../js/darkfish.js" defer></script>

<script src="../js/jquery-3.2.0.min.js"></script>

<script src="../js/vue.min.js"></script>
<script src="../js/js.cookie.min.js"></script>

<link href="../css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="../css/rdoc.css" rel="stylesheet">
<link href="../css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "../";
  var index_rel_prefix = "../";
  var darkModeCsseHref = "../css/rdoc-dm.css"
  var defaultModeCssHref = "../css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="module">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="../index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="../table_of_contents.html#pages">Pages</a>
    <a href="../table_of_contents.html#classes">Classes</a>
    <a href="../table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#module-Gem::Security-label-Signing+gems">Signing gems</a>
    <li><a href="#module-Gem::Security-label-Walkthrough">Walkthrough</a>
    <li><a href="#module-Gem::Security-label-Building+your+certificate">Building your certificate</a>
    <li><a href="#module-Gem::Security-label-Signing+Gems">Signing Gems</a>
    <li><a href="#module-Gem::Security-label-Manually+signing+gems">Manually signing gems</a>
    <li><a href="#module-Gem::Security-label-Signed+gems+and+security+policies">Signed gems and security policies</a>
    <li><a href="#module-Gem::Security-label-Certificate+chains">Certificate chains</a>
    <li><a href="#module-Gem::Security-label-Signing+certificates">Signing certificates</a>
    <li><a href="#module-Gem::Security-label-Manually+verifying+signatures">Manually verifying signatures</a>
    <li><a href="#module-Gem::Security-label-OpenSSL+Reference">OpenSSL Reference</a>
    <li><a href="#module-Gem::Security-label-Bugs-2FTODO">Bugs/TODO</a>
    <li><a href="#module-Gem::Security-label-Original+author">Original author</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-alt_name_or_x509_entry">::alt_name_or_x509_entry</a>
    <li ><a href="#method-c-create_cert">::create_cert</a>
    <li ><a href="#method-c-create_cert_email">::create_cert_email</a>
    <li ><a href="#method-c-create_cert_self_signed">::create_cert_self_signed</a>
    <li ><a href="#method-c-create_digest">::create_digest</a>
    <li ><a href="#method-c-create_key">::create_key</a>
    <li ><a href="#method-c-email_to_name">::email_to_name</a>
    <li ><a href="#method-c-get_public_key">::get_public_key</a>
    <li ><a href="#method-c-re_sign">::re_sign</a>
    <li ><a href="#method-c-reset">::reset</a>
    <li ><a href="#method-c-sign">::sign</a>
    <li ><a href="#method-c-trust_dir">::trust_dir</a>
    <li ><a href="#method-c-trusted_certificates">::trusted_certificates</a>
    <li ><a href="#method-c-write">::write</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="module-Gem::Security">
    <h1 id="module-Gem::Security" class="module">
      module Gem::Security
    </h1>

    <section class="description">
    
<h1 id="module-Gem::Security-label-Signing+gems">Signing gems<span><a href="#module-Gem::Security-label-Signing+gems">&para;</a> <a href="#top">&uarr;</a></span></h1>

<p>The <a href="Security.html"><code>Gem::Security</code></a> implements cryptographic signatures for gems.  The section below is a step-by-step guide to using signed gems and generating your own.</p>

<h2 id="module-Gem::Security-label-Walkthrough">Walkthrough<span><a href="#module-Gem::Security-label-Walkthrough">&para;</a> <a href="#top">&uarr;</a></span></h2>

<h3 id="module-Gem::Security-label-Building+your+certificate">Building your certificate<span><a href="#module-Gem::Security-label-Building+your+certificate">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>In order to start signing your gems, you’ll need to build a private key and a self-signed certificate.  Here’s how:</p>

<pre># build a private key and certificate for yourself:
$ gem cert --build you@example.com</pre>

<p>This could take anywhere from a few seconds to a minute or two, depending on the speed of your computer (public key algorithms aren’t exactly the speediest crypto algorithms in the world).  When it’s finished, you’ll see the files “gem-private_key.pem” and “gem-public_cert.pem” in the current directory.</p>

<p>First things first: Move both files to ~/.gem if you don’t already have a key and certificate in that directory.  Ensure the file permissions make the key unreadable by others (by default the file is saved securely).</p>

<p>Keep your private key hidden; if it’s compromised, someone can sign packages as you (note: PKI has ways of mitigating the risk of stolen keys; more on that later).</p>

<h3 id="module-Gem::Security-label-Signing+Gems">Signing Gems<span><a href="#module-Gem::Security-label-Signing+Gems">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>In RubyGems 2 and newer there is no extra work to sign a gem.  RubyGems will automatically find your key and certificate in your home directory and use them to sign newly packaged gems.</p>

<p>If your certificate is not self-signed (signed by a third party) RubyGems will attempt to load the certificate chain from the trusted certificates. Use <code>gem cert --add signing_cert.pem</code> to add your signers as trusted certificates.  See below for further information on certificate chains.</p>

<p>If you build your gem it will automatically be signed.  If you peek inside your gem file, you’ll see a couple of new files have been added:</p>

<pre>$ tar tf your-gem-1.0.gem
metadata.gz
metadata.gz.sig # metadata signature
data.tar.gz
data.tar.gz.sig # data signature
checksums.yaml.gz
checksums.yaml.gz.sig # checksums signature</pre>

<h3 id="module-Gem::Security-label-Manually+signing+gems">Manually signing gems<span><a href="#module-Gem::Security-label-Manually+signing+gems">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>If you wish to store your key in a separate secure location you’ll need to set your gems up for signing by hand.  To do this, set the <code>signing_key</code> and <code>cert_chain</code> in the gemspec before packaging your gem:</p>

<pre class="ruby"><span class="ruby-identifier">s</span>.<span class="ruby-identifier">signing_key</span> = <span class="ruby-string">&#39;/secure/path/to/gem-private_key.pem&#39;</span>
<span class="ruby-identifier">s</span>.<span class="ruby-identifier">cert_chain</span> = <span class="ruby-node">%w[/secure/path/to/gem-public_cert.pem]</span>
</pre>

<p>When you package your gem with these options set RubyGems will automatically load your key and certificate from the secure paths.</p>

<h3 id="module-Gem::Security-label-Signed+gems+and+security+policies">Signed gems and security policies<span><a href="#module-Gem::Security-label-Signed+gems+and+security+policies">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>Now let’s verify the signature.  Go ahead and install the gem, but add the following options: <code>-P HighSecurity</code>, like this:</p>

<pre># install the gem with using the security policy &quot;HighSecurity&quot;
$ sudo gem install your.gem -P HighSecurity</pre>

<p>The <code>-P</code> option sets your security policy – we’ll talk about that in just a minute.  Eh, what’s this?</p>

<pre>$ gem install -P HighSecurity your-gem-1.0.gem
ERROR:  While executing gem ... (Gem::Security::Exception)
    root cert /CN=you/DC=example is not trusted</pre>

<p>The culprit here is the security policy.  RubyGems has several different security policies.  Let’s take a short break and go over the security policies.  Here’s a list of the available security policies, and a brief description of each one:</p>
<ul><li>
<p><a href="Security.html#NoSecurity"><code>NoSecurity</code></a> - Well, no security at all.  Signed packages are treated like unsigned packages.</p>
</li><li>
<p><a href="Security.html#LowSecurity"><code>LowSecurity</code></a> - Pretty much no security.  If a package is signed then RubyGems will make sure the signature matches the signing certificate, and that the signing certificate hasn’t expired, but that’s it.  A malicious user could easily circumvent this kind of security.</p>
</li><li>
<p><a href="Security.html#MediumSecurity"><code>MediumSecurity</code></a> - Better than <a href="Security.html#LowSecurity"><code>LowSecurity</code></a> and <a href="Security.html#NoSecurity"><code>NoSecurity</code></a>, but still fallible.  <a href="Package.html"><code>Package</code></a> contents are verified against the signing certificate, and the signing certificate is checked for validity, and checked against the rest of the certificate chain (if you don’t know what a certificate chain is, stay tuned, we’ll get to that). The biggest improvement over <a href="Security.html#LowSecurity"><code>LowSecurity</code></a> is that <a href="Security.html#MediumSecurity"><code>MediumSecurity</code></a> won’t install packages that are signed by untrusted sources. Unfortunately, <a href="Security.html#MediumSecurity"><code>MediumSecurity</code></a> still isn’t totally secure – a malicious user can still unpack the gem, strip the signatures, and distribute the gem unsigned.</p>
</li><li>
<p><a href="Security.html#HighSecurity"><code>HighSecurity</code></a> - Here’s the bugger that got us into this mess. The <a href="Security.html#HighSecurity"><code>HighSecurity</code></a> policy is identical to the <a href="Security.html#MediumSecurity"><code>MediumSecurity</code></a> policy, except that it does not allow unsigned gems.  A malicious user doesn’t have a whole lot of options here; they can’t modify the package contents without invalidating the signature, and they can’t modify or remove signature or the signing certificate chain, or RubyGems will simply refuse to install the package.  Oh well, maybe they’ll have better luck causing problems for CPAN users instead :).</p>
</li></ul>

<p>The reason RubyGems refused to install your shiny new signed gem was because it was from an untrusted source.  Well, your code is infallible (naturally), so you need to add yourself as a trusted source:</p>

<pre># add trusted certificate
gem cert --add ~/.gem/gem-public_cert.pem</pre>

<p>You’ve now added your public certificate as a trusted source.  Now you can install packages signed by your private key without any hassle.  Let’s try the install command above again:</p>

<pre># install the gem with using the HighSecurity policy (and this time
# without any shenanigans)
$ gem install -P HighSecurity your-gem-1.0.gem
Successfully installed your-gem-1.0
1 gem installed</pre>

<p>This time RubyGems will accept your signed package and begin installing.</p>

<p>While you’re waiting for RubyGems to work it’s magic, have a look at some of the other security commands by running <code>gem help cert</code>:</p>

<pre>Options:
  -a, --add CERT                   Add a trusted certificate.
  -l, --list [FILTER]              List trusted certificates where the
                                   subject contains FILTER
  -r, --remove FILTER              Remove trusted certificates where the
                                   subject contains FILTER
  -b, --build EMAIL_ADDR           Build private key and self-signed
                                   certificate for EMAIL_ADDR
  -C, --certificate CERT           Signing certificate for --sign
  -K, --private-key KEY            Key for --sign or --build
  -A, --key-algorithm ALGORITHM    Select key algorithm for --build from RSA, DSA, or EC. Defaults to RSA.
  -s, --sign CERT                  Signs CERT with the key from -K
                                   and the certificate from -C
  -d, --days NUMBER_OF_DAYS        Days before the certificate expires
  -R, --re-sign                    Re-signs the certificate from -C with the key from -K</pre>

<p>We’ve already covered the <code>--build</code> option, and the <code>--add</code>, <code>--list</code>, and <code>--remove</code> commands seem fairly straightforward; they allow you to add, list, and remove the certificates in your trusted certificate list.  But what’s with this <code>--sign</code> option?</p>

<h3 id="module-Gem::Security-label-Certificate+chains">Certificate chains<span><a href="#module-Gem::Security-label-Certificate+chains">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>To answer that question, let’s take a look at “certificate chains”, a concept I mentioned earlier.  There are a couple of problems with self-signed certificates: first of all, self-signed certificates don’t offer a whole lot of security.  Sure, the certificate says Yukihiro Matsumoto, but how do I know it was actually generated and signed by matz himself unless he gave me the certificate in person?</p>

<p>The second problem is scalability.  Sure, if there are 50 gem authors, then I have 50 trusted certificates, no problem.  What if there are 500 gem authors?  1000?  Having to constantly add new trusted certificates is a pain, and it actually makes the trust system less secure by encouraging RubyGems users to blindly trust new certificates.</p>

<p>Here’s where certificate chains come in.  A certificate chain establishes an arbitrarily long chain of trust between an issuing certificate and a child certificate.  So instead of trusting certificates on a per-developer basis, we use the PKI concept of certificate chains to build a logical hierarchy of trust.  Here’s a hypothetical example of a trust hierarchy based (roughly) on geography:</p>

<pre>                    --------------------------
                    | rubygems@rubygems.org |
                    --------------------------
                                |
              -----------------------------------
              |                                 |
  ----------------------------    -----------------------------
  |  seattlerb@seattlerb.org |    | dcrubyists@richkilmer.com |
  ----------------------------    -----------------------------
       |                |                 |             |
---------------   ----------------   -----------   --------------
|   drbrain   |   |   zenspider  |   | pabs@dc |   | tomcope@dc |
---------------   ----------------   -----------   --------------</pre>

<p>Now, rather than having 4 trusted certificates (one for drbrain, zenspider, pabs@dc, and tomecope@dc), a user could actually get by with one certificate, the “rubygems@rubygems.org” certificate.</p>

<p>Here’s how it works:</p>

<p>I install “rdoc-3.12.gem”, a package signed by “drbrain”.  I’ve never heard of “drbrain”, but his certificate has a valid signature from the “seattle.rb@seattlerb.org” certificate, which in turn has a valid signature from the “rubygems@rubygems.org” certificate.  Voila!  At this point, it’s much more reasonable for me to trust a package signed by “drbrain”, because I can establish a chain to “rubygems@rubygems.org”, which I do trust.</p>

<h3 id="module-Gem::Security-label-Signing+certificates">Signing certificates<span><a href="#module-Gem::Security-label-Signing+certificates">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>The <code>--sign</code> option allows all this to happen.  A developer creates their build certificate with the <code>--build</code> option, then has their certificate signed by taking it with them to their next regional Ruby meetup (in our hypothetical example), and it’s signed there by the person holding the regional RubyGems signing certificate, which is signed at the next RubyConf by the holder of the top-level RubyGems certificate.  At each point the issuer runs the same command:</p>

<pre># sign a certificate with the specified key and certificate
# (note that this modifies client_cert.pem!)
$ gem cert -K /mnt/floppy/issuer-priv_key.pem -C issuer-pub_cert.pem
   --sign client_cert.pem</pre>

<p>Then the holder of issued certificate (in this case, your buddy “drbrain”), can start using this signed certificate to sign RubyGems.  By the way, in order to let everyone else know about his new fancy signed certificate, “drbrain” would save his newly signed certificate as <code>~/.gem/gem-public_cert.pem</code></p>

<p>Obviously this RubyGems trust infrastructure doesn’t exist yet.  Also, in the “real world”, issuers actually generate the child certificate from a certificate request, rather than sign an existing certificate.  And our hypothetical infrastructure is missing a certificate revocation system. These are that can be fixed in the future…</p>

<p>At this point you should know how to do all of these new and interesting things:</p>
<ul><li>
<p>build a gem signing key and certificate</p>
</li><li>
<p>adjust your security policy</p>
</li><li>
<p>modify your trusted certificate list</p>
</li><li>
<p>sign a certificate</p>
</li></ul>

<h2 id="module-Gem::Security-label-Manually+verifying+signatures">Manually verifying signatures<span><a href="#module-Gem::Security-label-Manually+verifying+signatures">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>In case you don’t trust RubyGems you can verify gem signatures manually:</p>
<ol><li>
<p>Fetch and unpack the gem</p>

<pre>gem fetch some_signed_gem
tar -xf some_signed_gem-1.0.gem</pre>
</li><li>
<p>Grab the public key from the gemspec</p>

<pre>gem spec some_signed_gem-1.0.gem cert_chain | \
  ruby -rpsych -e &#39;puts Psych.load($stdin)&#39; &gt; public_key.crt</pre>
</li><li>
<p>Generate a SHA1 hash of the data.tar.gz</p>

<pre class="ruby"><span class="ruby-identifier">openssl</span> <span class="ruby-identifier">dgst</span> <span class="ruby-operator">-</span><span class="ruby-identifier">sha1</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">data</span>.<span class="ruby-identifier">tar</span>.<span class="ruby-identifier">gz</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">my</span>.<span class="ruby-identifier">hash</span>
</pre>
</li><li>
<p>Verify the signature</p>

<pre>openssl rsautl -verify -inkey public_key.crt -certin \
  -in data.tar.gz.sig &gt; verified.hash</pre>
</li><li>
<p>Compare your hash to the verified hash</p>

<pre>diff -s verified.hash my.hash</pre>
</li><li>
<p>Repeat 5 and 6 with metadata.gz</p>
</li></ol>

<h2 id="module-Gem::Security-label-OpenSSL+Reference">OpenSSL Reference<span><a href="#module-Gem::Security-label-OpenSSL+Reference">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>The .pem files generated by –build and –sign are PEM files.  Here’s a couple of useful OpenSSL commands for manipulating them:</p>

<pre># convert a PEM format X509 certificate into DER format:
# (note: Windows .cer files are X509 certificates in DER format)
$ openssl x509 -in input.pem -outform der -out output.der

# print out the certificate in a human-readable format:
$ openssl x509 -in input.pem -noout -text</pre>

<p>And you can do the same thing with the private key file as well:</p>

<pre># convert a PEM format RSA key into DER format:
$ openssl rsa -in input_key.pem -outform der -out output_key.der

# print out the key in a human readable format:
$ openssl rsa -in input_key.pem -noout -text</pre>

<h2 id="module-Gem::Security-label-Bugs-2FTODO">Bugs/TODO<span><a href="#module-Gem::Security-label-Bugs-2FTODO">&para;</a> <a href="#top">&uarr;</a></span></h2>
<ul><li>
<p>There’s no way to define a system-wide trust list.</p>
</li><li>
<p>custom security policies (from a YAML file, etc)</p>
</li><li>
<p>Simple method to generate a signed certificate request</p>
</li><li>
<p>Support for OCSP, SCVP, CRLs, or some other form of cert status check (list is in order of preference)</p>
</li><li>
<p>Support for encrypted private keys</p>
</li><li>
<p>Some sort of semi-formal trust hierarchy (see long-winded explanation above)</p>
</li><li>
<p>Path discovery (for gem certificate chains that don’t have a self-signed root) – by the way, since we don’t have this, THE ROOT OF THE CERTIFICATE CHAIN MUST BE SELF SIGNED if <a href="Security/Policy.html#attribute-i-verify_root"><code>Policy#verify_root</code></a> is true (and it is for the <a href="Security.html#MediumSecurity"><code>MediumSecurity</code></a> and <a href="Security.html#HighSecurity"><code>HighSecurity</code></a> policies)</p>
</li><li>
<p>Better explanation of X509 naming (ie, we don’t have to use email addresses)</p>
</li><li>
<p>Honor AIA field (see note about OCSP above)</p>
</li><li>
<p>Honor extension restrictions</p>
</li><li>
<p>Might be better to store the certificate chain as a PKCS#7 or PKCS#12 file, instead of an array embedded in the metadata.</p>
</li></ul>

<h2 id="module-Gem::Security-label-Original+author">Original author<span><a href="#module-Gem::Security-label-Original+author">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Paul Duncan &lt;pabs@pablotron.org&gt; <a href="http://pablotron.org">pablotron.org</a>/</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="AlmostNoSecurity">AlmostNoSecurity
          <dd><p>AlmostNo security policy: only verify that the signing certificate is the one that actually signed the data.  Make no attempt to verify the signing certificate chain.</p>

<p>This policy is basically useless. better than nothing, but can still be easily spoofed, and is not recommended.</p>
          <dt id="DEFAULT_KEY_ALGORITHM">DEFAULT_KEY_ALGORITHM
          <dd><p>Default algorithm to use when building a key pair</p>
          <dt id="EC_NAME">EC_NAME
          <dd><p>Named curve used for Elliptic Curve</p>
          <dt id="EXTENSIONS">EXTENSIONS
          <dd><p>The default set of extensions are:</p>
<ul><li>
<p>The certificate is not a certificate authority</p>
</li><li>
<p>The key for the certificate may be used for key and data encipherment and digital signatures</p>
</li><li>
<p>The certificate contains a subject key identifier</p>
</li></ul>
          <dt id="HighSecurity">HighSecurity
          <dd><p>High security policy: only allow signed gems to be installed, verify the signing certificate, verify the signing certificate chain all the way to the root certificate, and only trust root certificates that we have explicitly allowed trust for.</p>

<p>This security policy is significantly more difficult to bypass, and offers a reasonable guarantee that the contents of the gem have not been altered.</p>
          <dt id="KEY_CIPHER">KEY_CIPHER
          <dd><p>Cipher used to encrypt the key pair used to sign gems. Must be in the list returned by OpenSSL::Cipher.ciphers</p>
          <dt id="LowSecurity">LowSecurity
          <dd><p>Low security policy: only verify that the signing certificate is actually the gem signer, and that the signing certificate is valid.</p>

<p>This policy is better than nothing, but can still be easily spoofed, and is not recommended.</p>
          <dt id="MediumSecurity">MediumSecurity
          <dd><p>Medium security policy: verify the signing certificate, verify the signing certificate chain all the way to the root certificate, and only trust root certificates that we have explicitly allowed trust for.</p>

<p>This security policy is reasonable, but it allows unsigned packages, so a malicious person could simply delete the package signature and pass the gem off as unsigned.</p>
          <dt id="NoSecurity">NoSecurity
          <dd><p>No security policy: all package signature checks are disabled.</p>
          <dt id="ONE_DAY">ONE_DAY
          <dd><p>One day in seconds</p>
          <dt id="ONE_YEAR">ONE_YEAR
          <dd><p>One year in seconds</p>
          <dt id="Policies">Policies
          <dd><p>Hash of configured security policies</p>
          <dt id="RSA_DSA_KEY_LENGTH">RSA_DSA_KEY_LENGTH
          <dd><p>Length of keys created by RSA and DSA keys</p>
          <dt id="SigningPolicy">SigningPolicy
          <dd><p><a href="Security/Policy.html"><code>Policy</code></a> used to verify a certificate and key when signing a gem</p>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-alt_name_or_x509_entry" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">alt_name_or_x509_entry</span><span
                                class="method-args">(certificate, x509_entry)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="alt_name_or_x509_entry-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 385</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">alt_name_or_x509_entry</span>(<span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">x509_entry</span>)
  <span class="ruby-identifier">alt_name</span> = <span class="ruby-identifier">certificate</span>.<span class="ruby-identifier">extensions</span>.<span class="ruby-identifier">find</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">extension</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">extension</span>.<span class="ruby-identifier">oid</span> <span class="ruby-operator">==</span> <span class="ruby-node">&quot;#{x509_entry}AltName&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">return</span> <span class="ruby-identifier">alt_name</span>.<span class="ruby-identifier">value</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">alt_name</span>

  <span class="ruby-identifier">certificate</span>.<span class="ruby-identifier">send</span> <span class="ruby-identifier">x509_entry</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-create_cert" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">create_cert</span><span
                                class="method-args">(subject, key, age = ONE_YEAR, extensions = EXTENSIONS, serial = 1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates an unsigned certificate for <code>subject</code> and <code>key</code>.  The lifetime of the key is from the current time to <code>age</code> which defaults to one year.</p>

<p>The <code>extensions</code> restrict the key to the indicated uses.</p>

                              <div class="method-source-code" id="create_cert-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 401</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">create_cert</span>(<span class="ruby-identifier">subject</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">age</span> = <span class="ruby-constant">ONE_YEAR</span>, <span class="ruby-identifier">extensions</span> = <span class="ruby-constant">EXTENSIONS</span>, <span class="ruby-identifier">serial</span> = <span class="ruby-value">1</span>)
  <span class="ruby-identifier">cert</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">Certificate</span>.<span class="ruby-identifier">new</span>

  <span class="ruby-identifier">cert</span>.<span class="ruby-identifier">public_key</span> = <span class="ruby-identifier">get_public_key</span>(<span class="ruby-identifier">key</span>)
  <span class="ruby-identifier">cert</span>.<span class="ruby-identifier">version</span>    = <span class="ruby-value">2</span>
  <span class="ruby-identifier">cert</span>.<span class="ruby-identifier">serial</span>     = <span class="ruby-identifier">serial</span>

  <span class="ruby-identifier">cert</span>.<span class="ruby-identifier">not_before</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
  <span class="ruby-identifier">cert</span>.<span class="ruby-identifier">not_after</span>  = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">age</span>

  <span class="ruby-identifier">cert</span>.<span class="ruby-identifier">subject</span>    = <span class="ruby-identifier">subject</span>

  <span class="ruby-identifier">ef</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">ExtensionFactory</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">cert</span>

  <span class="ruby-identifier">cert</span>.<span class="ruby-identifier">extensions</span> = <span class="ruby-identifier">extensions</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">ext_name</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">ef</span>.<span class="ruby-identifier">create_extension</span> <span class="ruby-identifier">ext_name</span>, <span class="ruby-identifier">value</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">cert</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-create_cert_email" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">create_cert_email</span><span
                                class="method-args">(email, key, age = ONE_YEAR, extensions = EXTENSIONS)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a self-signed certificate with an issuer and subject from <code>email</code>, a subject alternative name of <code>email</code> and the given <code>extensions</code> for the <code>key</code>.</p>

                              <div class="method-source-code" id="create_cert_email-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 440</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">create_cert_email</span>(<span class="ruby-identifier">email</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">age</span> = <span class="ruby-constant">ONE_YEAR</span>, <span class="ruby-identifier">extensions</span> = <span class="ruby-constant">EXTENSIONS</span>)
  <span class="ruby-identifier">subject</span> = <span class="ruby-identifier">email_to_name</span> <span class="ruby-identifier">email</span>

  <span class="ruby-identifier">extensions</span> = <span class="ruby-identifier">extensions</span>.<span class="ruby-identifier">merge</span> <span class="ruby-string">&quot;subjectAltName&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-node">&quot;email:#{email}&quot;</span>

  <span class="ruby-identifier">create_cert_self_signed</span> <span class="ruby-identifier">subject</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">age</span>, <span class="ruby-identifier">extensions</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-create_cert_self_signed" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">create_cert_self_signed</span><span
                                class="method-args">(subject, key, age = ONE_YEAR, extensions = EXTENSIONS, serial = 1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a self-signed certificate with an issuer and subject of <code>subject</code> and the given <code>extensions</code> for the <code>key</code>.</p>

                              <div class="method-source-code" id="create_cert_self_signed-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 452</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">create_cert_self_signed</span>(<span class="ruby-identifier">subject</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">age</span> = <span class="ruby-constant">ONE_YEAR</span>, <span class="ruby-identifier">extensions</span> = <span class="ruby-constant">EXTENSIONS</span>, <span class="ruby-identifier">serial</span> = <span class="ruby-value">1</span>)
  <span class="ruby-identifier">certificate</span> = <span class="ruby-identifier">create_cert</span> <span class="ruby-identifier">subject</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">age</span>, <span class="ruby-identifier">extensions</span>

  <span class="ruby-identifier">sign</span> <span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">key</span>, <span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">age</span>, <span class="ruby-identifier">extensions</span>, <span class="ruby-identifier">serial</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-create_digest" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">create_digest</span><span
                                class="method-args">(algorithm = DIGEST_NAME)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new digest instance using the specified <code>algorithm</code>. The default is SHA256.</p>

                              <div class="method-source-code" id="create_digest-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 462</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">create_digest</span>(<span class="ruby-identifier">algorithm</span> = <span class="ruby-constant">DIGEST_NAME</span>)
  <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">Digest</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">algorithm</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-create_key" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">create_key</span><span
                                class="method-args">(algorithm)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new key pair of the specified <code>algorithm</code>. RSA, DSA, and EC are supported.</p>

                              <div class="method-source-code" id="create_key-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 470</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">create_key</span>(<span class="ruby-identifier">algorithm</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span>)
    <span class="ruby-keyword">case</span> <span class="ruby-identifier">algorithm</span>.<span class="ruby-identifier">downcase</span>
    <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;dsa&quot;</span>
      <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">DSA</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">RSA_DSA_KEY_LENGTH</span>)
    <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;rsa&quot;</span>
      <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">RSA</span>.<span class="ruby-identifier">new</span>(<span class="ruby-constant">RSA_DSA_KEY_LENGTH</span>)
    <span class="ruby-keyword">when</span> <span class="ruby-string">&quot;ec&quot;</span>
      <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">EC</span>.<span class="ruby-identifier">generate</span>(<span class="ruby-constant">EC_NAME</span>)
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">raise</span> <span class="ruby-constant">Gem</span><span class="ruby-operator">::</span><span class="ruby-constant">Security</span><span class="ruby-operator">::</span><span class="ruby-constant">Exception</span>,
      <span class="ruby-node">&quot;#{algorithm} algorithm not found. RSA, DSA, and EC algorithms are supported.&quot;</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-email_to_name" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">email_to_name</span><span
                                class="method-args">(email_address)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Turns <code>email_address</code> into an OpenSSL::X509::Name</p>

                              <div class="method-source-code" id="email_to_name-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 489</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">email_to_name</span>(<span class="ruby-identifier">email_address</span>)
  <span class="ruby-identifier">email_address</span> = <span class="ruby-identifier">email_address</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/[^\w@.-]+/i</span>, <span class="ruby-string">&quot;_&quot;</span>)

  <span class="ruby-identifier">cn</span>, <span class="ruby-identifier">dcs</span> = <span class="ruby-identifier">email_address</span>.<span class="ruby-identifier">split</span> <span class="ruby-string">&quot;@&quot;</span>

  <span class="ruby-identifier">dcs</span> = <span class="ruby-identifier">dcs</span>.<span class="ruby-identifier">split</span> <span class="ruby-string">&quot;.&quot;</span>

  <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">X509</span><span class="ruby-operator">::</span><span class="ruby-constant">Name</span>.<span class="ruby-identifier">new</span>([
    [<span class="ruby-string">&quot;CN&quot;</span>, <span class="ruby-identifier">cn</span>],
    <span class="ruby-operator">*</span><span class="ruby-identifier">dcs</span>.<span class="ruby-identifier">map</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">dc</span><span class="ruby-operator">|</span> [<span class="ruby-string">&quot;DC&quot;</span>, <span class="ruby-identifier">dc</span>] },
  ])
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-get_public_key" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">get_public_key</span><span
                                class="method-args">(key)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Gets the right public key from a PKey instance</p>

                              <div class="method-source-code" id="get_public_key-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 425</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">get_public_key</span>(<span class="ruby-identifier">key</span>)
  <span class="ruby-comment"># Ruby 3.0 (Ruby/OpenSSL 2.2) or later</span>
  <span class="ruby-keyword">return</span> <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">key</span>.<span class="ruby-identifier">public_to_der</span>) <span class="ruby-keyword">if</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-value">:public_to_der</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">public_key</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">key</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">EC</span>)

  <span class="ruby-identifier">ec_key</span> = <span class="ruby-constant">OpenSSL</span><span class="ruby-operator">::</span><span class="ruby-constant">PKey</span><span class="ruby-operator">::</span><span class="ruby-constant">EC</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">key</span>.<span class="ruby-identifier">group</span>.<span class="ruby-identifier">curve_name</span>)
  <span class="ruby-identifier">ec_key</span>.<span class="ruby-identifier">public_key</span> = <span class="ruby-identifier">key</span>.<span class="ruby-identifier">public_key</span>
  <span class="ruby-identifier">ec_key</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-re_sign" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">re_sign</span><span
                                class="method-args">(expired_certificate, private_key, age = ONE_YEAR, extensions = EXTENSIONS)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Signs <code>expired_certificate</code> with <code>private_key</code> if the keys match and the expired certificate was self-signed.</p>

                              <div class="method-source-code" id="re_sign-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 508</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">re_sign</span>(<span class="ruby-identifier">expired_certificate</span>, <span class="ruby-identifier">private_key</span>, <span class="ruby-identifier">age</span> = <span class="ruby-constant">ONE_YEAR</span>, <span class="ruby-identifier">extensions</span> = <span class="ruby-constant">EXTENSIONS</span>)
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">Gem</span><span class="ruby-operator">::</span><span class="ruby-constant">Security</span><span class="ruby-operator">::</span><span class="ruby-constant">Exception</span>,
        <span class="ruby-string">&quot;incorrect signing key for re-signing &quot;</span> <span class="ruby-operator">+</span>
        <span class="ruby-identifier">expired_certificate</span>.<span class="ruby-identifier">subject</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-keyword">unless</span>
    <span class="ruby-identifier">expired_certificate</span>.<span class="ruby-identifier">check_private_key</span>(<span class="ruby-identifier">private_key</span>)

  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">expired_certificate</span>.<span class="ruby-identifier">subject</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">==</span>
         <span class="ruby-identifier">expired_certificate</span>.<span class="ruby-identifier">issuer</span>.<span class="ruby-identifier">to_s</span>
    <span class="ruby-identifier">subject</span> = <span class="ruby-identifier">alt_name_or_x509_entry</span> <span class="ruby-identifier">expired_certificate</span>, <span class="ruby-value">:subject</span>
    <span class="ruby-identifier">issuer</span>  = <span class="ruby-identifier">alt_name_or_x509_entry</span> <span class="ruby-identifier">expired_certificate</span>, <span class="ruby-value">:issuer</span>

    <span class="ruby-identifier">raise</span> <span class="ruby-constant">Gem</span><span class="ruby-operator">::</span><span class="ruby-constant">Security</span><span class="ruby-operator">::</span><span class="ruby-constant">Exception</span>,
          <span class="ruby-node">&quot;#{subject} is not self-signed, contact #{issuer} &quot;</span> \
          <span class="ruby-string">&quot;to obtain a valid certificate&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">serial</span> = <span class="ruby-identifier">expired_certificate</span>.<span class="ruby-identifier">serial</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>

  <span class="ruby-identifier">create_cert_self_signed</span>(<span class="ruby-identifier">expired_certificate</span>.<span class="ruby-identifier">subject</span>, <span class="ruby-identifier">private_key</span>, <span class="ruby-identifier">age</span>,
                          <span class="ruby-identifier">extensions</span>, <span class="ruby-identifier">serial</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-reset" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">reset</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Resets the trust directory for verifying gems.</p>

                              <div class="method-source-code" id="reset-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 533</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">reset</span>
  <span class="ruby-ivar">@trust_dir</span> = <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-sign" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">sign</span><span
                                class="method-args">(certificate, signing_key, signing_cert, age = ONE_YEAR, extensions = EXTENSIONS, serial = 1)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sign the public key from <code>certificate</code> with the <code>signing_key</code> and <code>signing_cert</code>, using the Gem::Security::DIGEST_NAME.  Uses the default certificate validity range and extensions.</p>

<p>Returns the newly signed certificate.</p>

                              <div class="method-source-code" id="sign-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 544</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">sign</span>(<span class="ruby-identifier">certificate</span>, <span class="ruby-identifier">signing_key</span>, <span class="ruby-identifier">signing_cert</span>, <span class="ruby-identifier">age</span> = <span class="ruby-constant">ONE_YEAR</span>, <span class="ruby-identifier">extensions</span> = <span class="ruby-constant">EXTENSIONS</span>, <span class="ruby-identifier">serial</span> = <span class="ruby-value">1</span>)
  <span class="ruby-identifier">signee_subject</span> = <span class="ruby-identifier">certificate</span>.<span class="ruby-identifier">subject</span>
  <span class="ruby-identifier">signee_key</span>     = <span class="ruby-identifier">certificate</span>.<span class="ruby-identifier">public_key</span>

  <span class="ruby-identifier">alt_name</span> = <span class="ruby-identifier">certificate</span>.<span class="ruby-identifier">extensions</span>.<span class="ruby-identifier">find</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">extension</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">extension</span>.<span class="ruby-identifier">oid</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;subjectAltName&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">extensions</span> = <span class="ruby-identifier">extensions</span>.<span class="ruby-identifier">merge</span> <span class="ruby-string">&quot;subjectAltName&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">alt_name</span>.<span class="ruby-identifier">value</span> <span class="ruby-keyword">if</span>
    <span class="ruby-identifier">alt_name</span>

  <span class="ruby-identifier">issuer_alt_name</span> = <span class="ruby-identifier">signing_cert</span>.<span class="ruby-identifier">extensions</span>.<span class="ruby-identifier">find</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">extension</span><span class="ruby-operator">|</span>
    <span class="ruby-identifier">extension</span>.<span class="ruby-identifier">oid</span> <span class="ruby-operator">==</span> <span class="ruby-string">&quot;subjectAltName&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">extensions</span> = <span class="ruby-identifier">extensions</span>.<span class="ruby-identifier">merge</span> <span class="ruby-string">&quot;issuerAltName&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">issuer_alt_name</span>.<span class="ruby-identifier">value</span> <span class="ruby-keyword">if</span>
    <span class="ruby-identifier">issuer_alt_name</span>

  <span class="ruby-identifier">signed</span> = <span class="ruby-identifier">create_cert</span> <span class="ruby-identifier">signee_subject</span>, <span class="ruby-identifier">signee_key</span>, <span class="ruby-identifier">age</span>, <span class="ruby-identifier">extensions</span>, <span class="ruby-identifier">serial</span>
  <span class="ruby-identifier">signed</span>.<span class="ruby-identifier">issuer</span> = <span class="ruby-identifier">signing_cert</span>.<span class="ruby-identifier">subject</span>

  <span class="ruby-identifier">signed</span>.<span class="ruby-identifier">sign</span> <span class="ruby-identifier">signing_key</span>, <span class="ruby-constant">Gem</span><span class="ruby-operator">::</span><span class="ruby-constant">Security</span><span class="ruby-operator">::</span><span class="ruby-constant">DIGEST_NAME</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-trust_dir" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">trust_dir</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a <a href="Security/TrustDir.html"><code>Gem::Security::TrustDir</code></a> which wraps the directory where trusted certificates live.</p>

                              <div class="method-source-code" id="trust_dir-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 572</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">trust_dir</span>
  <span class="ruby-keyword">return</span> <span class="ruby-ivar">@trust_dir</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@trust_dir</span>

  <span class="ruby-identifier">dir</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">join</span> <span class="ruby-constant">Gem</span>.<span class="ruby-identifier">user_home</span>, <span class="ruby-string">&quot;.gem&quot;</span>, <span class="ruby-string">&quot;trust&quot;</span>

  <span class="ruby-ivar">@trust_dir</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Gem</span><span class="ruby-operator">::</span><span class="ruby-constant">Security</span><span class="ruby-operator">::</span><span class="ruby-constant">TrustDir</span>.<span class="ruby-identifier">new</span> <span class="ruby-identifier">dir</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-trusted_certificates" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">trusted_certificates</span><span
                                class="method-args">(&amp;block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Enumerates the trusted certificates via <a href="Security/TrustDir.html"><code>Gem::Security::TrustDir</code></a>.</p>

                              <div class="method-source-code" id="trusted_certificates-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 583</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">trusted_certificates</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">trust_dir</span>.<span class="ruby-identifier">each_certificate</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-c-write" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">write</span><span
                                class="method-args">(pemmable, path, permissions = 0o600, passphrase = nil, cipher = KEY_CIPHER)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Writes <code>pemmable</code>, which must respond to <code>to_pem</code> to <code>path</code> with the given <code>permissions</code>. If passed <code>cipher</code> and <code>passphrase</code> those arguments will be passed to <code>to_pem</code>.</p>

                              <div class="method-source-code" id="write-source">
            <pre><span class="ruby-comment"># File rubygems/security.rb, line 592</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">write</span>(<span class="ruby-identifier">pemmable</span>, <span class="ruby-identifier">path</span>, <span class="ruby-identifier">permissions</span> = <span class="ruby-value">0o600</span>, <span class="ruby-identifier">passphrase</span> = <span class="ruby-keyword">nil</span>, <span class="ruby-identifier">cipher</span> = <span class="ruby-constant">KEY_CIPHER</span>)
  <span class="ruby-identifier">path</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span> <span class="ruby-identifier">path</span>

  <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span> <span class="ruby-identifier">path</span>, <span class="ruby-string">&quot;wb&quot;</span>, <span class="ruby-identifier">permissions</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">io</span><span class="ruby-operator">|</span>
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">passphrase</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">cipher</span>
      <span class="ruby-identifier">io</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">pemmable</span>.<span class="ruby-identifier">to_pem</span> <span class="ruby-identifier">cipher</span>, <span class="ruby-identifier">passphrase</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">io</span>.<span class="ruby-identifier">write</span> <span class="ruby-identifier">pemmable</span>.<span class="ruby-identifier">to_pem</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-identifier">path</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

